//package com.xuecheng.media.config.rocketmq;
//
//import lombok.extern.slf4j.Slf4j;
//import org.apache.rocketmq.client.exception.MQClientException;
//import org.apache.rocketmq.client.producer.DefaultMQProducer;
//import org.apache.rocketmq.client.producer.TransactionMQProducer;
//import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;
//import org.apache.rocketmq.spring.core.RocketMQTemplate;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.boot.context.properties.EnableConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.util.Assert;
//
//@Slf4j
//@Configuration
//@EnableConfigurationProperties(RocketMQProperties.class)
//public class RocketMQConfig {
//
//    private final RocketMQProperties properties;
//
//    @Autowired
//    public RocketMQConfig(RocketMQProperties properties) {
//        this.properties = properties;
//    }
//
//    @Bean
//    @ConditionalOnProperty(prefix = "rocketmq", name = "name-server")
//    public RocketMQTemplate rocketMQTemplate() {
//        log.info("Initializing RocketMQTemplate for group: {}", properties.getProducerGroup());
//
//        // 创建事务生产者（TransactionMQProducer）
//        TransactionMQProducer producer = new TransactionMQProducer(properties.getProducerGroup());
//        producer.setNamesrvAddr(properties.getNameServer());
//        producer.setSendMsgTimeout(properties.getSendTimeout());
//        producer.setRetryTimesWhenSendFailed(properties.getRetryTimes());
//        producer.setMaxMessageSize(properties.getMaxMessageSize());
//        producer.setVipChannelEnabled(properties.isVipChannelEnabled());
//
//        // 创建模板并绑定生产者
//        RocketMQTemplate template = new RocketMQTemplate();
//        template.setProducer(producer);
//
//        log.info("RocketMQTemplate configured successfully");
//        log.info(">>>> 正在创建RocketMQTemplate实例 <<<<");
//        log.info(">>>> 实例内存地址: {} <<<<", System.identityHashCode(template));
//        return template;
//    }
//}